import polymonkey.time.*;

// the Time object that is used to count deltaTime
Time time;

// TimerEvents 
TimerEvent firstTimer;
TimerEvent secondTimer;
TimerEvent thirdTimer;

PFont font;


void setup()
{
  size(300, 150);

  //counting time
  time = new Time(this);

  // 3 TimerEvents for 1,2,3 seconds 
  firstTimer = new TimerEvent( this, time, 1.0);
  secondTimer = new TimerEvent(this, time, 1.0);  
  thirdTimer = new TimerEvent( this, time, 1.0);
  
  // it's just the font
  font = createFont("garamond", 20);
  textFont(font);
  textAlign(LEFT, TOP);

  noStroke();
  background(255);
}

void draw()
{
  // this is just the fading background trick. nothing to see here
  fill(255, 16);
  rect(0, 0, width, height);

  fill(0);
  
  // Using the TimerEvent methods of getCurrentTime() and getTargetTime() we can make progress bars of time  
  rect(0, 100, norm(firstTimer.getCurrentTime(), 0, firstTimer.getTargetTime()) * 100, 10);

  rect(100, 100, norm(secondTimer.getCurrentTime(), 0, secondTimer.getTargetTime()) * 100, 10);

  rect(200, 100, norm(thirdTimer.getCurrentTime(), 0, thirdTimer.getTargetTime()) * 100, 10);

  fill(255);
  rect(0, 110, width, height);

  fill(0);
  text("time = " + nf(time.getCountTime(), 1 , 1) + "s", 10, 120);

}


// The timerEvent method. This method will be called at the frame on or right after the target time.
void timerEvent(TimerEvent sw)
{
  fill(0);
  
  // with multipal TimerEvents you can check to see which one fired the event.
  if(sw == firstTimer)
  {
    rect(0, 0, 100, 100); 
  }
  if(sw == secondTimer)
  {
    rect(100, 0, 100, 100); 
  }
  if(sw == thirdTimer)
  {
    rect(200, 0, 100, 100); 
  }  
}







